//图片懒加载 v-du-lazy="item"
import { useIntersectionObserver } from '@vueuse/core'

const dulazyFun = (el, binding) => {
  const { stop } = useIntersectionObserver(el, ([{ isIntersecting }], observerElement) => {
    if (isIntersecting) {
      el.src = binding.value
      stop()
    }
  })
}

export const dulazy = {
  mounted(el, binding) {
    dulazyFun(el, binding)
  },
  updated(el, binding) {
    dulazyFun(el, binding)
  },
}
